package cn.cdeden.knowledge.controller.watermark;


import cn.cdeden.common.core.domain.R;
import cn.cdeden.common.core.utils.page.TableDataInfo;
import cn.cdeden.knowledge.domain.dto.FileWatermarkConfigDto;
import cn.cdeden.knowledge.domain.dto.FileWatermarkConfigQueryParam;
import cn.cdeden.knowledge.enums.FilesWatermarkConfigEnums;
import cn.cdeden.knowledge.service.FilesWatermarkConfigService;
import cn.dev33.satoken.annotation.SaIgnore;
import io.undertow.util.BadRequestException;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * 文件:水印配置管理
 */
@RestController
@RequiredArgsConstructor
//@Api(tags = "文件:水印配置管理")
@RequestMapping("/api/fileWatermarkConfig")
public class FileWatermarkConfigController {

    private final FilesWatermarkConfigService fileWatermarkConfigService;

    /**
     * 水印:查询库文件水印配置
     * @param query
     * @param pageable
     * @return
     */
    @GetMapping("/library/query")
//    @Log("水印:查询库文件水印配置")
//    @ApiOperation("水印:查询文件水印配置")
    public R<TableDataInfo<FileWatermarkConfigDto>> libraryQuery(FileWatermarkConfigQueryParam query, Pageable pageable) throws BadRequestException {
        TableDataInfo<FileWatermarkConfigDto> info = fileWatermarkConfigService.libraryQuery(query, pageable);
        return R.ok(info);
    }


    /**
     * 文件:查询水印配置
     * @return
     */
//    @AnonymousGetMapping("/query/config")
    @SaIgnore
    @GetMapping("/query/config")
//    @Log("文件:查询水印配置")
//    @ApiOperation("文件:查询水印配置")
    public R queryConfig() {
        FilesWatermarkConfigEnums[] values = FilesWatermarkConfigEnums.values();
        List<Map<String, Object>> objects = Arrays.stream(values).map(item -> {
            Map<String, Object> map = new HashMap<>();
            map.put("configCode",item.getConfigCode());
            map.put("configName",item.getConfigName());
            map.put("configType",item.getConfigType());
            map.put("code",item.getCode());
            return map;
        }).collect(Collectors.toList());



        return  R.ok(objects);
//        return  BaseRespResult.successResult(objects);
    }

}
